	<article class="module width_full">
		<header><h3 class="tabs_involved">DANH SÁCH NGƯỜI DÙNG</h3>
		<ul class="tabs">
   			<li><a href="#tab1">Tất cả</a></li>
    		<li><a href="#tab2">Quản trị viên</a></li>
			<li><a href="#tab3">Khách hàng</a></li>
		</ul>
		</header>
		<div class="tab_container"  style="overflow-y:scroll; height:200px">
			<div id="tab1" class="tab_content">
			<table class="tablesorter" cellspacing="0" > 
			<thead> 
				<tr> 
   					<th></th> 
    				<th>Username</th> 
    				<th>Email</th> 
    				<th>Quyền hạn</th> 
    				<th>Hành động</th> 
				</tr> 
			</thead> 
			<tbody id="alluser"> 
			<?php
				foreach($user as $value)
				{
					echo "<tr id='row".$value->id."'>";
   					echo '<td><input type="checkbox"></td>';
    				echo '<td>'.$value->username.'</td>';
    				echo '<td>'.$value->email.'</td>'; 
    				echo '<td>'.$value->permission.'</td>';
    				echo "<td><a class='edit-link' href='".$value->id."'><input type='image' src='".base_url()."public/admin/images/icn_edit.png' title='Chỉnh sửa người dùng'></a>
					<a class='delete-link' href='".$value->id."'><input type='image' src='".base_url()."public/admin/images/icn_trash.png'title='Xóa người dùng'></a>
					<a class='add-link'><input type='image' src='".base_url()."public/admin/images/icn_add_user.png' title='Thêm người dùng mới'></a></td>";				
					echo '</tr>';
				}
			?>
			</tbody> 
			</table>
			</div><!-- end of #tab1 -->
			
			<div id="tab2" class="tab_content">
			<table class="tablesorter" cellspacing="0" > 
			<thead> 
				<tr> 
   					<th></th> 
    				<th>Username</th> 
    				<th>Email</th> 
    				<th>Quyền hạn</th> 
    				<th>Hành động</th> 
				</tr> 
			</thead> 
			<tbody id="adminuser"> 
			<?php
				foreach($admin as $value)
				{
					echo "<tr id='row".$value->id."'>";
   					echo '<td><input type="checkbox"></td>';
    				echo '<td>'.$value->username.'</td>';
    				echo '<td>'.$value->email.'</td>'; 
    				echo '<td>'.$value->permission.'</td>';
    				echo "<td><a class='edit-link' href='".$value->id."'><input type='image' src='".base_url()."public/admin/images/icn_edit.png' title='Chỉnh sửa người dùng'></a>
					<a class='delete-link' href='".$value->id."'><input type='image' src='".base_url()."public/admin/images/icn_trash.png'title='Xóa người dùng'></a>
					<a class='add-link'><input type='image' src='".base_url()."public/admin/images/icn_add_user.png' title='Thêm người dùng mới'></a></td>";				
					echo '</tr>';
				}
			?>
			</tbody> 
			</table>
			</div><!-- end of #tab1 -->
			
			<div id="tab3" class="tab_content">
			<table class="tablesorter" cellspacing="0" > 
			<thead> 
				<tr> 
   					<th></th> 
    				<th>Username</th> 
    				<th>Email</th> 
    				<th>Quyền hạn</th> 
    				<th>Hành động</th> 
				</tr> 
			</thead> 
			<tbody id="customeruser"> 
			<?php
				foreach($customer as $value)
				{
					echo "<tr id='row".$value->id."'>";
   					echo '<td><input type="checkbox"></td>';
    				echo '<td>'.$value->username.'</td>';
    				echo '<td>'.$value->email.'</td>'; 
    				echo '<td>'.$value->permission.'</td>';
    				echo "<td><a class='edit-link' href='".$value->id."'><input type='image' src='".base_url()."public/admin/images/icn_edit.png' title='Chỉnh sửa người dùng'></a>
					<a class='delete-link' href='".$value->id."'><input type='image' src='".base_url()."public/admin/images/icn_trash.png'title='Xóa người dùng'></a>
					<a class='add-link'><input type='image' src='".base_url()."public/admin/images/icn_add_user.png' title='Thêm người dùng mới'></a></td>";				
					echo '</tr>';
				}
			?>
			</tbody> 
			</table>
			</div><!-- end of #tab1 -->			
			
		</div><!-- end of .tab_container -->
		
	</article><!-- end of content manager article -->	
<form id="edit_form" class="contact_form" method="post" name="contact_form">
</form>
<form id="add_form" class="contact_form" method="post" name="contact_form">
</form>
<script>
	$(document).ready(function() {
	   $('.edit-link').click(function(e) {
			e.preventDefault();
			var id_user=$(this).attr("href");
			$.ajax({
				type: "POST",
				url: globalurl+'index.php/admin/edituser',
				data: {
					id_user: id_user              
				},
				success: function(data) {
					$('#edit_form').toggle("slow");
					$('#edit_form').html(data);

				}
			});     
			
		}); 

	   $('.delete-link').click(function(e) {
			e.preventDefault();
			var id_user=$(this).attr("href");
			if (confirm('Bạn có muốn xóa người dùng này?')){
				$.ajax({
					type: "POST",
					url: globalurl+'index.php/admin/deleteuser',
					data: {
						id_user: id_user              
					},
					success: function(data) {
						$('#row'+id_user).hide();
					}
				});  
			}			
			
		}); 
		
	   $('#edit_form').submit(function(e){
			e.preventDefault();
			var id_user=$('#userid').val();
			var name_user=$('#username').val();
			var email_user=$('#email').val();
			var permission_user=$('#permission option:selected').val();
			var password_user=$('#password').val();
				$.ajax({
					type: "POST",
					url: globalurl+'index.php/admin/updateuser',
					data: {
						id_user: id_user,
						username: name_user,
						email: email_user,
						permission: permission_user,
						password: password_user
					},
					success: function(data) {
						$('#row'+id_user).html(data);
						$('#edit_form').toggle("slow");					
						
					}
				});  
			
			
		});	

	   $('.add-link').click(function(e) {
			e.preventDefault();	
				$.ajax({
					type: "POST",
					url: globalurl+'index.php/admin/view_adduser',
					data: {
					},
					success: function(data) {
						$('#add_form').html(data);	
						$('#add_form').toggle("slow");					
						
					}
				});  
			
			
		});		

	   $('#add_form').submit(function(e){
			e.preventDefault();
			var name_user=$('#username').val();
			var email_user=$('#email').val();
			var permission_user=$('#permission').val();
			var password_user=$('#password').val();				
				$.ajax({
					type: "POST",
					url: globalurl+'index.php/admin/addnewuser',
					data: {
						username: name_user,
						email: email_user,
						permission: permission_user,
						password: password_user					
					},
					success: function(data) {
						$('#alluser').append(data);
						if(permission_user=='1')
						{
							$('#adminuser').append(data);
						}
						else $('#customeruser').append(data);
						$('#add_form').toggle("slow");
						
					}
				});  
			
			
		});		

		
	});	
	
</script>

